package com.wzh.mysending.base;

import android.content.Context;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.annotation.Nullable;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.squareup.picasso.Picasso;
import com.wzh.mysending.R;
import com.wzutils.LogUtils;
import com.wzutils.SPUtils;

/**
 * Created by Hu on 2017/3/14.
 */

public class BaseActivity extends AppCompatActivity {
    Boolean isDebug = null;
    private static final String TAG = "BaseActivity";
    public Context context;
    public View emptyView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        context = this;
        isDebug = LogUtils.isDebug();
        emptyView=View.inflate(context, R.layout.empty_view,null);
    }



    public void setTitleBar(Toolbar toolbar, String title) {
        toolbar.setTitle(title.trim());
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    public void setRefresh(SwipeRefreshLayout myRefreshLayout) {
        myRefreshLayout.setColorSchemeResources(
                android.R.color.holo_blue_light, android.R.color.holo_red_light,
                android.R.color.holo_orange_light, android.R.color.holo_green_light);
    }
    public void toast(Object o) {
        if (o instanceof Integer) {
            Toast.makeText(context, (Integer) o, Toast.LENGTH_SHORT).show();
        } else if (o instanceof CharSequence) {
            Toast.makeText(context, (CharSequence) o, Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(context, o + "", Toast.LENGTH_SHORT).show();
        }

    }

    public void setImage(String url, ImageView imageView){
        Picasso.with(context)
                .load(url)
                .placeholder(R.mipmap.logo)
                .error(R.mipmap.logo)
                .into(imageView);
    }




    public <T> T $(int viewID, View heardView) {
        return (T) heardView.findViewById(viewID);
    }
    public void setRecy(RecyclerView recy) {

        recy.setHasFixedSize(true);
        recy.setLayoutManager(new LinearLayoutManager(context));
//        recy.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
    }

    // 下面四个是默认tag的函数
    public void i(String msg) {
        if (isDebug)
            Log.i(TAG, msg);
    }

    public void d(String msg) {
        if (isDebug)
            Log.d(TAG, msg);
    }

    public void e(String msg) {
        if (isDebug)
            Log.e(TAG, msg);
    }

    public void v(String msg) {
        if (isDebug)
            Log.v(TAG, msg);
    }

    // 下面是传入自定义tag的函数
    public void i(String tag, String msg) {
        if (isDebug)
            Log.i(tag, msg);
    }

    public void d(String tag, String msg) {
        if (isDebug)
            Log.i(tag, msg);
    }

    public void e(String tag, String msg) {
        if (isDebug)
            Log.i(tag, msg);
    }

    public void v(String tag, String msg) {
        if (isDebug)
            Log.i(tag, msg);
    }
    public void put(String key, Object object) {
        SPUtils.put(context, key, object);
    }

    public Object get(String key, Object object) {
        return SPUtils.get(context, key, object);
    }
}
